package mysql

import (
	"gorm.io/gorm"
	"person/personrpc/personrpc"
)

type User struct {
	gorm.Model
	Account  string `gorm:"type:varchar(30);comment:用户账号"`
	Password string `gorm:"type:varchar(32);comment:用户密码"`
}

func (u *User) FindCreate(db *gorm.DB, account string) error {
	return db.Debug().Where("account=?", account).FirstOrCreate(u).Error
}

func (u *User) FindUser(db *gorm.DB, id uint) error {
	return db.Debug().Where("id=?", id).Find(u).Error
}

func (u *User) Updata(db *gorm.DB) error {
	return db.Debug().Updates(&u).Error
}
func ShowUser(db *gorm.DB, id int64) ([]*personrpc.UserShow, error) {
	var show []*personrpc.UserShow
	db.Debug().Model(&User{}).Select(
		"account",
		"password",
	).Where("id=?", id).First(&show)
	return show, err
}
